package com.kaka.bus.engine.borrow.pact;

import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;

import javax.inject.Inject;

/**
 * Created by zhangqi on 2016/10/24.
 */

public class PactPresenter extends RxPresenter<PactContract.View> implements PactContract.Presenter{

    @Inject
    public PactPresenter(DataManager dataManager) {
        super(dataManager);
    }


    @Override
    public void getPactInfo(String userId, String token,String device) {
        addSubscribe(mDataManager
                .getApi()
                .getSignHtml(userId,token,device)
                .compose(T.D())
                .subscribeWith(new Result<String>() {
                    @Override
                    protected void onSuccess(String data) {
                        mView.getPactInfoSuccess(data);

                    }

                    @Override
                    public void onError(Throwable t) {
                        super.onError(t);
                        mView.netError(t);
                    }
                }));
    }

    @Override
    public void commitPact(String userId, String borrowId, String token) {
        mView.showDialog("签约中..");
        addSubscribe(mDataManager
                .getApi()
                .commitPact(userId,borrowId,token)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<String>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<String> wrapper) {
                        mView.pactSuccess(wrapper);
                    }

                    @Override
                    protected void onFinish() {
                        super.onFinish();
                        mView.dissDialog();
                    }
                }));
    }
}
